<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px" />
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('mid')" prop="mid" label="主键" />
        <el-table-column v-if="columns.visible('inviteCode')" prop="inviteCode" label="邀请码" />
        <el-table-column v-if="columns.visible('account')" prop="account" label="账号" />
        <el-table-column v-if="columns.visible('levelName')" prop="levelName" label="会员名称" />
        <el-table-column v-if="columns.visible('memberLevel')" prop="memberLevel" label="会员等级" />
        <el-table-column v-if="columns.visible('name')" prop="name" label="名称" />
        <el-table-column v-if="columns.visible('headImage')" prop="headImage" label="头像">
          <template slot-scope="scope">
            <img :src="scope.row.headImage" width="40">
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('addTime')" prop="addTime" label="注册时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.addTime,'{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('registerIp')" prop="registerIp" label="注册ip" />
        <el-table-column v-if="columns.visible('moeny')" prop="moeny" label="余额" />
        <el-table-column v-if="columns.visible('orderCommission')" prop="orderCommission" label="订单收益" />
        <el-table-column v-if="columns.visible('teamCommission')" prop="teamCommission" label="团队收益" />
        <el-table-column v-if="columns.visible('teamCount')" prop="teamCount" label="团队人数" />
        <el-table-column v-if="columns.visible('isIdent')" prop="isIdent" label="是否实名">
          <template slot-scope="scope">
            <el-tag>{{ statusIderifly[scope.row.isIdent] }}</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudMhzMember from '@/api/user/mhzMember'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '会员管理', url: 'api/mhzMember', sort: 'mid,desc', crudMethod: { ...crudMhzMember }})
const defaultForm = { mid: null, inviteCode: null, account: null, levelName: null, memberLevel: null, name: null, addTime: null, registerIp: null, moeny: null, orderCommission: null, teamCommission: null, teamCount: null, isIdent: null, headImage: null, pwd: null, salt: null }
export default {
  name: 'MhzMember',
  components: { pagination },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      statusIderifly: ['未实名', '已实名', '审核中', '驳回'],
      permission: {
        add: ['admin', 'mhzMember:add'],
        edit: ['admin', 'mhzMember:edit'],
        del: ['admin', 'mhzMember:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'account', display_name: '账号' },
        { key: 'memberLevel', display_name: '会员等级' },
        { key: 'name', display_name: '名称' }
      ]
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    }
  }
}
</script>

<style scoped>

</style>
